package extract.knowledge.edgeclass;

import com.thinkaurelius.titan.core.TitanGraph;
import common.model.knowledge.EdgeClassDoc;
import extract.knowledge.general.BaseTransformer;
import extract.knowledge.general.NodeParser;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import common.dao.gremlin.TitanGraphDao;

import javax.inject.Inject;

/**0
 * Created by Common on 8/1/16.
 */
@Component
public class EdgeClassTransformer extends BaseTransformer {
    final Logger logger = LoggerFactory.getLogger(EdgeClassTransformer.class);

    private TitanGraphDao titandb;
    private TitanGraph graph;
    private EdgeClassFactory edgeclass_factory;

    @Inject
    public EdgeClassTransformer(TitanGraphDao titandb
    ){
        this.titandb = titandb;
        this.graph = this.titandb.getTitanGraph();
        this.edgeclass_factory = new EdgeClassFactory(this.graph);
    }

    public boolean addProperties(Vertex edgeclass, EdgeClassDoc edgeclass_doc){
        return true;
    }



    public boolean transformEdgeClass(EdgeClassDoc edgeclass_doc){
        logger.debug("[transform edgeclass] edgeclass doc = \n{}", edgeclass_doc.toString());
        String id_node = edgeclass_doc.getId();
        Integer id = NodeParser.parse_id(id_node);
        String  label = NodeParser.parse_label( id_node );
        logger.debug("[transform edgeclass] lablel = {}, id = {}", label ,id);
        if(id == -1){
            logger.error("invalid id, ignore.");
            return false;
        }
        Vertex edgeclass = this.edgeclass_factory.getOrCreateVertex(id);

        return true;
    }


}
